const enterpriseVue = new Vue({
  el: "#app",
  data() {
    // var checkIDCard = (rule, value, callback) => {
    //   if (!value) {
    //     return callback(new Error("身份证号不能为空"));
    //   }
    //   setTimeout(() => {
    //     if (!ID_Validity(value)) {
    //       callback(new Error("请输入正确的身份证号"));
    //     }
    //   }, 100);
    // };
    return {
      pickerOptions: pickerOptions,
      rules: {
        Employee_Name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
        ],
        Service_Category: [
          { required: true, message: "请选择服务类型", trigger: "blur" },
        ],
        Mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        Gender: [{ required: true, message: "请选择性别", trigger: "blur" }],
        Nation: [{ required: true, message: "请选择民族", trigger: "blur" }],
        Education: [{ required: true, message: "请选择学历", trigger: "blur" }],
        Residence_Address: [
          { required: true, message: "请输入户籍地址", trigger: "blur" },
        ],
        Current_Residence_Address: [
          { required: true, message: "请输入现住址", trigger: "blur" },
        ],
        Household_Register_Class: [
          { required: true, message: "请输入户口性质", trigger: "blur" },
        ],
        Entry_Date: [
          { required: true, message: "请选择入职日期", trigger: "blur" },
        ],
        Departure_Date: [
          { required: true, message: "请选择离职日期", trigger: "blur" },
        ],
        Contract_SerialNumber: [
          { required: true, message: "请输入合同流水号", trigger: "blur" },
        ],
        // ID_Number: [
        //   {
        //     validator: checkIDCard,
        //     trigger: "blur",
        //   },
        // ],
      },
      value1: [],
      city: [],
      Service_Category: ["送货员", "部门主管", "技术人员", "测试人员"],
      form: {
        Employee_SerialNumber: "",
        Employee_Name: "",
        Service_Category: "",
        Mobile: "",
        ID_Number: "",
        Gender: "",
        Nation: "",
        Education: "",
        Residence_Address: "",
        Current_Residence_Address: "",
        Household_Register_Class: "",
        Entry_Date: "",
        Departure_Date: "",
        Contract_SerialNumber: "",
        Supplementary_Insurance: 0,
        DingTalk_UserID: "",
        Enterprise_Info_SerialNumber: "",
      },
      loading: false,
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    handleID() {
      const that = this;
      if (this.form.Mobile) {
        $.ajax({
          url: `${BASE_URL1}/Getbymobile`,
          type: "POST",
          data: {
            mobile: this.form.Mobile,
          },
          success: function (res) {
            if (res.errmsg === "ok") {
              that.form.DingTalk_UserID = res.result.userid;
            } else {
              that.$message.error("获取失败");
            }
          },
          dataType: "json",
        });
      } else {
        this.$message({
          type: "warning",
          message: "请输入手机号",
        });
      }
    },
    getData() {
      const that = this;
      $.ajax({
        url: absolutepath() + "utils/city.json",
        type: "GET",
        success: function (data) {
          that.city = data;
        },
        dataType: "json",
      });
    },
    submitForm(formName) {
      const that = this;
      // this.$refs[formName].validate((valid) => {
      //   if (valid) {
      that.loading = true;
      that.form.Residence_Address =
        this.value1[0] + "/" + this.value1[1] + "/" + this.value1[2];
      console.log(that.form);
      that.form.Enterprise_Info_SerialNumber = sessionStorage.getItem(
        "Enterprise_Info_SerialNumber"
      );
      console.log(that.form.Enterprise_Info_SerialNumber);
      let lArray = new Array();
      lArray.push(that.form);
      let lJSONObject_employee = new Object();
      lJSONObject_employee.employee = lArray; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Add = lJSONObject_employee; //换表
      // return;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (res) {
          if (res.Status === "success") {
            that.$message.success("提交成功");
            window.history.go(-1);
          } else {
            that.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      //   } else {
      //     console.log("error submit!!");
      //     return false;
      //   }
      // });
    },
  },
});
